//
//  OneSGSCViewController.m
//  HNJYB
//
//  Created by Mag1cPanda on 16/8/2.
//  Copyright © 2016年 Mag1cPanda. All rights reserved.
//

#import "DESCript.h"
#import "IDyz.h"
#import "JCAlertView.h"
#import "MoreSGSCGroup.h"
#import "OneSGSCViewController.h"
//#import "OneTipsViewController.h"
#import "InsuranceReportVC.h"
#import "QRadioButton.h"
#import "SGSCView.h"
#import "SRBlockButton.h"
#import "ZRRDView.h"
#import "AccidentPlaceView.h"
#import "WSDatePickerView.h"
#import "DJCameraViewController.h"

@interface OneSGSCViewController ()
<UITextFieldDelegate,
DJCameraViewControllerDelegate>
{
    UIScrollView *scroll;

    JCAlertView *jcAlert;

    QRadioButton *smallBtn;
    QRadioButton *bigBtn;

    NSMutableDictionary *bean;

    MoreSGSCGroup *partyAGroup;

    JCAlertView *endAlert;

    NSString *carno;
    
    AccidentPlaceView *sgdd;
    
    ZRRDView *sgsj;
    
}
@end

@implementation OneSGSCViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"事故上传";

    bean = [NSMutableDictionary dictionary];
    NSString *appcaseno = GlobleInstance.appcaseno;
    [bean setValue:appcaseno forKey:@"appcaseno"];

    NSString *imagelon = [NSString stringWithFormat:@"%f", GlobleInstance.imagelon];
    NSString *imagelat = [NSString stringWithFormat:@"%f", GlobleInstance.imagelat];
    [bean setValue:imagelon forKey:@"caselon"];
    [bean setValue:imagelat forKey:@"caselat"];
    
    
    NSString *currentDateStr = [self getCurrentTime];
    [bean setValue:currentDateStr forKey:@"alarmtime"];

    [bean setValue:GlobleInstance.areaid forKey:@"areaid"];
    [bean setValue:GlobleInstance.userflag forKey:@"username"];
    NSString *pwd = [UserDefaultsUtil getDataForKey:@"password"];
    pwd = [DESCript encrypt:pwd encryptOrDecrypt:kCCEncrypt key:[Util getKey]];
    [bean setValue:pwd forKey:@"password"];

    [bean setValue:GlobleInstance.token forKey:@"token"];
    //    [bean setValue:@"1" forKey:@"accidenttype"];
    [bean setValue:@"1" forKey:@"disposetype"];

    [self initScroll];

    [self ocrAutofill];
    
    //获取事故地址
    [self getCasehaplace];
}

-(NSString *)getCurrentTime
{
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    //用[NSDate date]可以获取系统当前时间
    NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
    //输出格式为：2010-10-27 10:22:13
    NSLog(@"%@", currentDateStr);
    
    return currentDateStr;
}

-(void)selectTime
{
    NSMutableString *tmp = [NSMutableString stringWithFormat:@"%@",sgsj.contentField.text];
    
    if (tmp.length < 1) {
        return;
    }
    
    NSString *maxDateStr = [tmp substringToIndex:tmp.length-3];
    
    NSDate *maxDate = [NSDate date:maxDateStr WithFormat:@"yyyy-MM-dd HH:mm"];
    
    WSDatePickerView *datePicker = [[WSDatePickerView alloc] initWithDateStyle:DateStyleShowYearMonthDayHourMinute currentDate:maxDate CompleteBlock:^(NSDate *startDate) {
        NSString *date = [startDate stringWithFormat:@"yyyy-MM-dd HH:mm:00"];
        NSLog(@"时间： %@",date);
        
        sgsj.contentField.text = date;
        
    }];
    
    datePicker.currentDate = maxDate;
    datePicker.maxLimitDate = maxDate;
    datePicker.doneButtonColor = [UIColor orangeColor];//确定按钮的颜色
    
    [datePicker show];
}

#pragma mark - 重新拍照识别
-(void)retakePhoto:(UIButton *)btn
{
    DJCameraViewController *cameraVC = [DJCameraViewController new];
    if (btn == partyAGroup.xmBtn) {
        cameraVC.titleStr1 = @"甲方驾驶证照片";
        cameraVC.guideImageName = @"jsznf";
        cameraVC.index = 4;
    }
    
    if (btn == partyAGroup.cphBtn) {
        cameraVC.titleStr1 = @"甲方行驶证照片";
        cameraVC.guideImageName = @"xsznf";
        cameraVC.index = 5;
    }
    
    cameraVC.isLandscape = YES;
    cameraVC.isShowWarnImage = YES;
    cameraVC.delegate = self;
    [self presentViewController:cameraVC animated:YES completion:nil];
}

#pragma mark - 相机代理
- (void)cameraViewController:(DJCameraViewController*)cameraVC ToObtainCameraPhotos:(UIImage*)image
{
    NSString* imageStr = [Util imageToString:image];
    
    NSNumber* type;
    if (cameraVC.index == 4) {
        type = @6;
    }
    if (cameraVC.index == 5) {
        type = @7;
    }
    
    NSMutableDictionary *imageBean = [NSMutableDictionary dictionary];
    
    NSString* userflag = [NSString stringWithFormat:@"%@", GlobleInstance.userflag];
    NSString* token = [NSString stringWithFormat:@"%@", GlobleInstance.token];
    [imageBean setValue:userflag forKey:@"userflag"];
    [imageBean setValue:token forKey:@"token"];
    [imageBean setObject:imageStr forKey:@"imageurl"];
    [imageBean setValue:type forKey:@"imagetype"];
    
    MBProgressHUD *imageHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    imageHud.label.text = @"正在识别，请稍候...";
    
    [LSHttpManager requestUrl:HNServiceURL serviceName:@"hnjjappOCR" parameters:imageBean complete:^(id result, ResultType resultType) {
        
        [imageHud hideAnimated:YES];
        NSLog(@"hnjjappOCR ~ %@",result);
        if ([result[@"data"] isKindOfClass:[NSDictionary class]]) {
            if (cameraVC.index == 4) {
                
                GlobleInstance.jfocrname = result[@"data"][@"ocrname"];
                GlobleInstance.jfocrcardno = result[@"data"][@"ocrcardno"];
                partyAGroup.xmView.field.text = GlobleInstance.jfocrname;
                partyAGroup.jszView.field.text = GlobleInstance.jfocrcardno;
            }
            if (cameraVC.index == 5) {
                
                GlobleInstance.jfocrcarno = result[@"data"][@"ocrcarno"];
                GlobleInstance.jfocrvin = result[@"data"][@"ocrvin"];
                
                if (GlobleInstance.jfocrcarno.length == 7)
                {
                    NSString *jfRegion = [GlobleInstance.jfocrcarno substringWithRange:NSMakeRange(0, 1)];
                    NSString *jfCarNumber = [GlobleInstance.jfocrcarno substringFromIndex:1];
                    partyAGroup.selectList.contentLab.text = jfRegion;
                    partyAGroup.cphView.field.text = jfCarNumber;
                }
                
                partyAGroup.cjhView.field.text = GlobleInstance.jfocrvin;
            }
        }
    }];
}


#pragma mark - 获取事故地址
-(void)getCasehaplace
{
    NSMutableDictionary *placeBean = [NSMutableDictionary dictionary];
    [placeBean setValue:GlobleInstance.userflag forKey:@"userflag"];
    [placeBean setValue:GlobleInstance.token forKey:@"token"];
    [placeBean setValue:GlobleInstance.appcaseno forKey:@"appcaseno"];
    
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];
    
    [LSHttpManager requestUrl:HNServiceURL serviceName:@"jjappgetplace" parameters:placeBean complete:^(id result, ResultType resultType) {
        
//        [hud hideAnimated:true];
        NSLog(@"jjappgetplace ~ %@",result);
        
        if ([result[@"restate"] isEqualToString:@"1"])
        {
            if ([result[@"data"] isEqualToString:@""]) {
                //如果没有获取到定位地址，说明不是从历史进入 直接取
                sgdd.contentView.text = GlobleInstance.imageaddress;
            }
            
            else {
                sgdd.contentView.text = result[@"data"];
            }
            
            
        }
        
    }];
    
}

- (void)ocrAutofill
{
    NSMutableDictionary *ocrBean = [NSMutableDictionary dictionary];
    [ocrBean setValue:GlobleInstance.userflag forKey:@"userflag"];
    [ocrBean setValue:GlobleInstance.token forKey:@"token"];
    [ocrBean setValue:GlobleInstance.appcaseno forKey:@"appcaseno"];
    
    MBProgressHUD *ocrHud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [LSHttpManager requestUrl:HNServiceURL serviceName:@"jjappgetOCRdata" parameters:ocrBean complete:^(id result, ResultType resultType) {
        
        [ocrHud hideAnimated:YES];
        NSLog(@"jjappgetOCRdata ~ %@",result);

        
        if ([result[@"data"] isKindOfClass:[NSArray class]]) {
            
            for (NSDictionary *dic in result[@"data"]) {
                if ([dic[@"imagetype"] isEqual:@"6"])
                {
                    GlobleInstance.jfocrname = dic[@"ocrname"];
                    GlobleInstance.jfocrcardno = dic[@"ocrcardno"];
                }
                if ([dic[@"imagetype"] isEqual:@"7"])
                {
                    GlobleInstance.jfocrcarno = dic[@"ocrcarno"];
                    GlobleInstance.jfocrvin = dic[@"ocrvin"];
                    GlobleInstance.jfocrcartype = dic[@"ocrcartype"];
                }
            }
            
            if (result[@"casehaptime"]) {
                sgsj.contentField.text = result[@"casehaptime"];
            }
        }
        
        /**********************************************/
        
        if ([GlobleInstance.jfocrcartype hasPrefix:@"小型"])
        {
            partyAGroup.radio1.checked = YES;
        }
        else
        {
            partyAGroup.radio2.checked = YES;
        }
        
        partyAGroup.xmView.field.text = GlobleInstance.jfocrname;
        
        if ([Util cheackLicense:GlobleInstance.jfocrcarno] || [Util checkLearnLicense:GlobleInstance.jfocrcarno] )
        {
            NSString *region = [GlobleInstance.jfocrcarno substringWithRange:NSMakeRange(0, 1)];
            NSString *carNumber = [GlobleInstance.jfocrcarno substringFromIndex:1];
            
            if ([partyAGroup.selectList.dataArray containsObject:region]) {
                partyAGroup.selectList.contentLab.text = region;
            }
            
            partyAGroup.cphView.field.text = carNumber;
        }
        
        partyAGroup.jszView.field.text = GlobleInstance.jfocrcardno;
        partyAGroup.cjhView.field.text = GlobleInstance.jfocrvin;
        
    }];
    
}

#pragma mark - TextField Delegate
//- (void)textFieldDidEndEditing:(UITextField *)textField
//{
//    if (textField == partyAGroup.cphView.field)
//    {
//        NSString *tmpStr = [textField.text uppercaseString];
//        tmpStr = [tmpStr stringByReplacingOccurrencesOfString:@" " withString:@""];
//        textField.text = tmpStr;
//        
//    }
//    
//    if (textField == partyAGroup.jszView.field || textField == partyAGroup.cjhView.field) {
//        NSString *tmpStr = [textField.text uppercaseString];
//        tmpStr = [tmpStr stringByReplacingOccurrencesOfString:@" " withString:@""];
//        textField.text = tmpStr;
//    }
//}


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if ([string isEqualToString:@""]) {
        return YES;
    }

    char commitChar = [string characterAtIndex:0];

    if (commitChar>96 && commitChar<123) {
        //小写变成大写
        NSString * uppercaseString = string.uppercaseString;

        NSString * str1 = [textField.text substringToIndex:range.location];

        NSString * str2 = [textField.text substringFromIndex:range.location];

        textField.text = [NSString stringWithFormat:@"%@%@%@",str1,uppercaseString,str2];

        return NO;
    }
    return YES;
}


#pragma mark - 获取保单号
- (void)getBdhCode
{
    //拼接车牌
    carno = [NSString stringWithFormat:@"%@%@", partyAGroup.selectList.contentLab.text, partyAGroup.cphView.field.text];
    
    if (!([Util cheackLicense:carno] || [Util checkLearnLicense:carno]))
    {
        SHOWALERT(@"请填写正确的车牌号");
        return;
    }

    if (partyAGroup.isLinPai || ![carno hasPrefix:@"豫"]) {
        if (![Util checkChaimsNO:partyAGroup.cjhView.field.text])
        {
            SHOWALERT(@"请填写正确的车架号");
            return;
        }
    }

    NSString *temStr = carno;
    NSString *frameno = partyAGroup.cjhView.field.text;
    NSMutableDictionary *bdhBean = [NSMutableDictionary dictionary];
    [bdhBean setValue:temStr forKey:@"casecarno"];
    [bdhBean setValue:[frameno uppercaseString] forKey:@"frameno"];
    [bdhBean setValue:GlobleInstance.userflag forKey:@"userflag"];
    [bdhBean setValue:GlobleInstance.appcaseno forKey:@"appcaseno"];
    [bdhBean setValue:GlobleInstance.token forKey:@"token"];
    [bdhBean setValue:@"" forKey:@"policyno"];

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:true];

    [LSHttpManager requestUrl:HNServiceURL serviceName:@"jjappkckpSearchCpsNum" parameters:bdhBean complete:^(id result, ResultType resultType) {

      [hud hideAnimated:true];

      NSLog(@"获取保单号 -> %@", result);

      if ([result[@"restate"] isEqualToString:@"1"])
      {
          partyAGroup.bdhView.field.text = result[@"data"][@"trafficinsno"];
      }

      else
      {
          MBProgressHUD *tHud = [MBProgressHUD showHUDAddedTo:self.view animated:NO];
          tHud.mode = MBProgressHUDModeText;
          tHud.label.text = @"未查询到保单号，请手动输入";
          [tHud hideAnimated:NO afterDelay:1.5];
      }

    }];
}

- (void)initScroll
{
    scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 64)];
    scroll.backgroundColor = HNBackColor;
    [self.view addSubview:scroll];

    UILabel *topLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, ScreenWidth-20, 40)];
    topLab.font = [UIFont systemFontOfSize:16];
    topLab.textColor = [UIColor lightGrayColor];
    topLab.numberOfLines = 0;
    topLab.textAlignment = NSTextAlignmentCenter;
    topLab.text = @"请输入车牌号和联系方式，便于事故处理";
    [scroll addSubview:topLab];
    
    UIColor *backColor = RGB(234, 234, 234);
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, topLab.maxY+10, ScreenWidth, 150)];
    backView.backgroundColor = backColor;
    [scroll addSubview:backView];
    
    sgsj = [[ZRRDView alloc] initWithFrame:CGRectMake(10, 10, ScreenWidth-20, 50)];
    sgsj.titleLab.text = @"事故时间:";
    sgsj.titleLab.textColor = [UIColor redColor];
    sgsj.contentField.delegate = self;
//    sgsj.contentField.placeholder = @"请选择时间";
    sgsj.contentField.enabled = false;
    sgsj.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectTime)];
    [sgsj addGestureRecognizer:tap];
    [backView addSubview:sgsj];
    
    sgdd = [[AccidentPlaceView alloc] initWithFrame:CGRectMake(10, sgsj.maxY+10, ScreenWidth-20, 70)];
    sgdd.contentView.x = sgdd.contentView.x - 20;
    [backView addSubview:sgdd];
    
    partyAGroup = [[MoreSGSCGroup alloc] initWithFrame:CGRectMake(0, backView.maxY+10, ScreenWidth, 585) groupId:@"partyAGroup"];
    partyAGroup.backgroundColor = backColor;
    partyAGroup.title = @"事故车主信息";
    partyAGroup.cphView.field.delegate = self;
    partyAGroup.jszView.field.delegate = self;
    partyAGroup.cjhView.field.delegate = self;
    partyAGroup.lxdhView.field.keyboardType = UIKeyboardTypePhonePad;
    [scroll addSubview:partyAGroup];

    //给获取按钮添加点击事件
    [partyAGroup.codeBtn addTarget:self action:@selector(getBdhCode) forControlEvents:1 << 6];
    [partyAGroup.xmBtn addTarget:self action:@selector(retakePhoto:) forControlEvents:1<<6];
    [partyAGroup.cphBtn addTarget:self action:@selector(retakePhoto:) forControlEvents:1<<6];
    
    
    SRBlockButton *submitBtn = [[SRBlockButton alloc] initWithFrame:CGRectMake(10, partyAGroup.maxY + 20, ScreenWidth - 20, 50) title:@"提交" titleColor:[UIColor whiteColor] handleBlock:^(SRBlockButton *btn) {

        //拼接车牌
        carno = [NSString stringWithFormat:@"%@%@", partyAGroup.selectList.contentLab.text, partyAGroup.cphView.field.text];
        
        if (!partyAGroup.selectedIndex)
        {
            SHOWALERT(@"请选择车型");
            return;
        }
        
        if ([partyAGroup.xmView.field.text isEqualToString:@""])
        {
            SHOWALERT(@"请填写姓名");
            return;
        }
        
        if (!([Util cheackLicense:carno] || [Util checkLearnLicense:carno]))
        {
            SHOWALERT(@"请填写正确的车牌号");
            return;
        }
        
        if (![Util isMobileNumber:partyAGroup.lxdhView.field.text])
        {
            SHOWALERT(@"请填写正确的联系电话");
            return;
        }
        
        if (![IDyz validateIDCardNumber:partyAGroup.jszView.field.text])
        {
            SHOWALERT(@"请填写正确的驾驶证号");
            return;
        }
        
        if (partyAGroup.isLinPai || ![carno hasPrefix:@"豫"]) {
            if (![Util checkChaimsNO:partyAGroup.cjhView.field.text])
            {
                SHOWALERT(@"请填写正确的车架号");
                return;
            }
        }
        
        else {
            if (partyAGroup.cjhView.field.text.length < 1) {
                SHOWALERT(@"车架号为空");
                return;
            }
        }
        
        
        if (partyAGroup.isLinPai || ![carno hasPrefix:@"豫"]) {
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请人工核实外省或临牌车辆的证件信息真伪" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"认可提交"style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                [self uploadCaseInfo];
                
            }];
            [alertController addAction:okAction];
            
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"人工核实"style:UIAlertActionStyleDefault handler:nil];
            [alertController addAction:cancelAction];
            
            [self presentViewController:alertController animated:YES completion:nil];
        }
        
        //河南非临牌
        else {
            [self uploadCaseInfo];
        }
      
    }];
    submitBtn.backgroundColor = HNBlue;
    submitBtn.layer.cornerRadius = 5;
    submitBtn.clipsToBounds = YES;
    [scroll addSubview:submitBtn];
    
    scroll.contentSize = CGSizeMake(ScreenWidth, submitBtn.maxY+20);

    //交警账号
    if (UserType == TrafficPolice)
    {
        sgdd.contentView.userInteractionEnabled = YES;
    }
    
    //协警账号
    else
    {
        sgdd.contentView.userInteractionEnabled = NO;
    }
}

-(void)uploadCaseInfo
{
    [bean setValue:carno forKey:@"casecarno"];
    [bean setValue:partyAGroup.lxdhView.field.text forKey:@"appphone"];
    
    NSString *accidentplace = [NSString stringWithFormat:@"%@", sgdd.contentView.text];
    [bean setValue:accidentplace forKey:@"accidentplace"];
    [bean setValue:GlobleInstance.imageaddress forKey:@"casehaplace"];
    
    NSString *casehaptime = [NSString stringWithFormat:@"%@", sgsj.contentField.text];
    [bean setValue:casehaptime forKey:@"casehaptime"];
    
    NSArray *arr = @[ @{ @"carownname" : partyAGroup.xmView.field.text,
                         @"carownphone" : partyAGroup.lxdhView.field.text,
                         @"casecarno" : carno,
                         @"cartype" : partyAGroup.selectedIndex,
                         @"frameno" : [partyAGroup.cjhView.field.text uppercaseString],
                         @"cardno" : [partyAGroup.jszView.field.text uppercaseString],
                         @"policyno" : partyAGroup.bdhView.field.text,
                         @"driverlicence" : partyAGroup.jszView.field.text,
                         @"dutytype" : @"0",
                         @"temporary":[NSString stringWithFormat:@"%d",partyAGroup.isLinPai]
                         }
                    ];
    
    [bean setObject:[Util objectToJson:arr] forKey:@"casecarlist"];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    
    [LSHttpManager requestUrl:HNServiceURL serviceName:@"hnkckpjjappsubmitCaseInfor" parameters:bean complete:^(id result, ResultType resultType) {
        
        [hud hideAnimated:YES];
        if (result)
        {
            NSLog(@"%@", JsonResult);
        }
        
        if ([result[@"restate"] isEqualToString:@"1"])
        {
//            OneTipsViewController *vc = [OneTipsViewController new];
//            [self.navigationController pushViewController:vc animated:YES];
            
            GlobleInstance.casecarno = carno;
            GlobleInstance.casetelephone = partyAGroup.lxdhView.field.text;
            GlobleInstance.casehaptime = sgsj.contentField.text;
            GlobleInstance.casecarlist = arr;
            
            InsuranceReportVC *vc = [InsuranceReportVC new];
            [self.navigationController pushViewController:vc animated:YES];
        }
        
        else if ([result[@"restate"] isEqualToString:@"-12"]) {
            
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示"message:result[@"redes"] preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定"style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                [self.navigationController popToRootViewControllerAnimated:YES];
                
            }];
            
            
            [alertController addAction:okAction];
            
            [self presentViewController:alertController animated:YES completion:nil];
        }
        
        else
        {
            SHOWALERT(result[@"redes"]);
        }
        
    }];

}

- (void)showAlertView
{
    UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth - 60, 200)];
    customView.backgroundColor = [UIColor whiteColor];
    customView.layer.cornerRadius = 5;
    customView.clipsToBounds = YES;

    UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(customView.width / 2 - 30, 20, 60, 60)];
    icon.image = [UIImage imageNamed:@"IP030"];
    [customView addSubview:icon];

    UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, icon.maxY + 20, customView.width, 20)];
    lab.font = HNFont(14);
    lab.text = @"事故上传成功，是否立即返回首页";
    lab.textColor = [UIColor darkGrayColor];
    lab.textAlignment = NSTextAlignmentCenter;
    [customView addSubview:lab];

    UIView *horizontalLine = [[UIView alloc] initWithFrame:CGRectMake(0, lab.maxY + 20, customView.width, 1)];
    horizontalLine.backgroundColor = RGB(235, 235, 235);
    [customView addSubview:horizontalLine];
    UIView *verticalLine = [[UIView alloc] initWithFrame:CGRectMake(customView.width / 2, lab.maxY + 20, 1, 60)];
    verticalLine.backgroundColor = RGB(235, 235, 235);
    [customView addSubview:verticalLine];

    UIColor *color = [UIColor blackColor];

    SRBlockButton *confirmBtn = [[SRBlockButton alloc] initWithFrame:CGRectMake(0, lab.maxY + 21, customView.width / 2, 60) title:@"确认" titleColor:color handleBlock:^(SRBlockButton *btn) {

      [jcAlert dismissWithCompletion:^{

        NSArray *arr = self.navigationController.viewControllers;
        [self.navigationController popToViewController:arr[1] animated:YES];

      }];

    }];
    [customView addSubview:confirmBtn];

    SRBlockButton *cancelBtn = [[SRBlockButton alloc] initWithFrame:CGRectMake(confirmBtn.maxX + 1, lab.maxY + 21, customView.width / 2, 60) title:@"暂不" titleColor:color handleBlock:^(SRBlockButton *btn) {

      [jcAlert dismissWithCompletion:^{

      }];

    }];
    [customView addSubview:cancelBtn];

    jcAlert = [[JCAlertView alloc] initWithCustomView:customView dismissWhenTouchedBackground:YES];
    [jcAlert show];
}

@end
